import { queryProject } from '../services/api';

const defaultProjDetail = {
  projectName: '',
  version: '',
  testTime: '',
  tester: '',
  manager: '',
  features: '',
  modify: '',
  notes: '',
  record: [],
};

export default {
  namespace: 'item',

  state: {
    status: undefined,
    projDetail: defaultProjDetail,
    projTestSheet: [],
  },

  effects: {
    *fetchProject({ payload }, { call, put }) {
      const reponse = yield call(queryProject, payload);
      yield put({
        type: 'change',
        payload: {
          status: reponse.status,
          projDetail: reponse.data,
        },
      });
    },
    *clearProject(_, { put }) {
      yield put({
        type: 'change',
        payload: {
          status: undefined,
          projDetail: defaultProjDetail,
        },
      });
    },
  },

  reducers: {
    change(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
